package com.starleague.battletech.unit.mech.jpa.appengine;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import com.starleague.battletech.unit.mech.MechHitLocationPosition;

@Entity(name = "MECH_CORE_COMPONENT_CRITICAL_SLOT")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class MechCoreComponentCriticalSlotGae
        extends MechCriticalSlotGae
{
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private MechCoreComponentGae coreComponent;

    MechCoreComponentCriticalSlotGae(MechCoreComponentGae coreComponent,
                                     MechHitLocationPosition position,
                                     int index)
    {
        super(position, index);
        this.coreComponent = coreComponent;
    }

    protected MechCoreComponentCriticalSlotGae()
    {
        //
    }

    @Transient
    @Override
    public MechCoreComponentGae getComponent()
    {
        return this.coreComponent;
    }

    @Override
    public String toStringSingleLine()
    {
        return (this.coreComponent.getActuatorType() != null)
                ? "[" + this.coreComponent.getActuatorType() + "] " + this.getId()
                : "[" + this.coreComponent.getCoreComponentType() + "] " + this.getId();
    }
}
